<!DOCTYPE html>
<html>
<head>
<title>首页</title>
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="format-detection" content="telephone=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />

<link rel="alternate icon" type="image/png" href="assets/i/favicon.png">
<link rel="stylesheet" href="assets/css/amazeui.min.css" />
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="js/main.js"></script>
<script src="js/md5.js"></script>
<style type="text/css">
.am-navbar-nav a:hover {color: #E066FF;}

.am-navbar-nav a:active {color: #E999FF; background-color:#AFA;}

</style>
<script type="text/javascript">
	$(document).ready(function() {
		var dat = getSessionValue("index");
		if(dat){
			var datObj = JSON.parse(dat);
			$("#signnum").text(datObj.sumsignmerchant);
			$("#sumrecordal").text(datObj.sumrecordalmerchant);
		}
	});

	function listMerchants(type, pageindex) {
		
		var reqData = new RequestData('listMerchant.action');
		var userid = window.sessionStorage.getItem("userid");
		if (userid) {
			reqData.userid = userid;
		} else {
			popAlert("您尚未登录！");
			toPage("login.html");
		}
		reqData.registerflag = 0;
		reqData.recordalflag = 0;
		if (type == 1) {
			reqData.registerflag = 1;
		} else {
			reqData.recordalflag = 1;
		}
		reqData.pageindex = pageindex;
		reqData.itemsperpage = 10;
		var jsonstr = JSON.stringify(reqData);
		console.log(jsonstr);
		//return;
		$.ajax({
			cache : false,
			type : "POST",
			crossDomain : true,
			url : testUrl,
			data : jsonstr, //你的formid
			async : true,
			error : function(request) {
				alert("Connection error");
			},
			success : function(data) {
				var dataObj = eval("(" + data + ")");
				if (dataObj.ret == 1) {
					//console.log(dataObj);
					var jsonObj = JSON.stringify(dataObj.rows);
					window.sessionStorage.setItem("mresults", jsonObj);
					location.href =  "mresult.html?opt="+type;// "searchresult.html?opt="+type;
				} else {
					popAlert(dataObj.msg);
					//resetForm();
				}

			}
		});

	}
	function startgps() {
		//var gps = navigator.geolocation;
		//alert(1);
		//if (gps) {
		//	alert(2);
		//	gps.getCurrentPosition(signIn, function(error) {
		//		popAlert("Got an error, code: " + error.code + " message: "+ error.message);
		//	}, {
		//		maximumAge : 10000
		//	}); // 这里设置超时为10000毫秒，即10秒
		//} 
		
		
		
		var geolocation = new $.AMUI.Geolocation();
		 console.log(geolocation);
		 geolocation.get({timeout: 7000}).then(function(position){
			 signIn(position);
			
		}, function(err) {
	    popAlert('获取地理位置时发生错误，错误信息：<br>' + err);
	    console.log(err);
	  });
	}
	function signIn(position) {
		if (position) {
			var latitude = position.coords.latitude;
			var longitude = position.coords.longitude;
			var reqData = new RequestData('signIn.action');
			var userid = window.sessionStorage.getItem("userid");
			if (userid) {
				reqData.userid = userid;
			} else {
				popAlert("您尚未登录！");
				toPage("login.html");
			}
			reqData.position =  longitude+ "," + latitude;
			var jsonstr = JSON.stringify(reqData);
			$.ajax({ 
				cache : false,
				type : "POST",
				crossDomain : true,
				url : testUrl,
				data : jsonstr, //你的formid
				async : false,
				error : function(request) {
					popAlert("Connection error");
				},
				success : function(data) {
					var dataObj = eval("(" + data + ")");				
					if (dataObj.ret == 1) {
						popAlert("签到成功!");			
					}else{
						popAlert("签到失败!");			
					}
				}
			});
		} else
			alert("position is null...");
	}
</script>

</head>
<body>
	<header data-am-widget="header" class="am-header am-header-default">
		<div class="am-header-left am-header-nav">
			<a href="#left-link" class=""> <i
				class="am-header-icon am-icon-home"></i> </a>
		</div>
		<h1 class="am-header-title">
			<a href="#title-link" class=""> 车夫登记 </a>
		</h1>

		<div class="am-header-right am-header-nav">
			<a href="javascript:void(0)" class=""> <i
				class="am-header-icon am-icon-bars"></i> </a>
				
		</div>
	</header>

	<div data-am-widget="list_news" class="am-list-news am-list-news-default">
		<div class="am-list-news-bd">
			<ul class="am-list">
				<li class="am-g am-list-item-dated"><a href="#"
					class="am-list-item-hd ">您本月已签约商家：<span id="signnum"></span>
				</a></li>
				<li class="am-g am-list-item-dated"><a href="#"
					class="am-list-item-hd ">您已备案商家：
						<span id="sumrecordal"></span>
				</a></li>

			</ul>
		</div>
	</div>
	<!-- 
<div class="am-vertical-align" style="height: 150px;">
  <div class="am-vertical-align-middle">
		<ul data-role="listview">
				<li><span>您本月已签约商家：</span> <span id="signnum"></span>
				</li>
				 <hr data-am-widget="divider" style="" class="am-divider am-divider-dotted" />
				<li><span>您已备案商家：</span> <span id="sumrecordal"></span>
				</li>
				 <hr data-am-widget="divider" style="" class="am-divider am-divider-dotted" />
			</ul>
  </div>
</div>
 -->
	<div class="am-g">
		<div class="am-u-sm-9 am-u-sm-centered">
			<a href="mquery.html" class="am-btn am-btn-secondary am-btn-block"><i
				class="am-icon-search am-icon-lg"></i>查找商家</a>
		</div>
	</div>


	<div data-am-widget="navbar" class="am-navbar am-cf am-navbar-default "
		id="">
		<ul class="am-navbar-nav am-cf am-avg-sm-3">
			<li><a href="#" class="" onclick="listMerchants(1,1)"> <img
					src="assets/i/Information.png"
					alt="登记" /> <span class="am-navbar-label">登记过的商家</span> </a></li>
			<li><a href="#" class="" onclick="listMerchants(0,1)"> <img
					src="assets/i/Information.png"
					alt="备案" /> <span class="am-navbar-label">已备案的商家</span> </a></li>

			<li><a href="#" class="" onclick="startgps()"> 
			<img src="assets/i/map.png" alt="定位" /> <span class="am-navbar-label">签到</span>
			</a></li>
		</ul>
	</div>
</body>
</html>
